<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
  
  <head>
    <title>药品添加</title>
    <jsp:include page="header.jsp"></jsp:include>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/lib/kindeditor/themes/default/default.css" />
    <script charset="utf-8" src="${pageContext.request.contextPath }/lib/kindeditor/kindeditor-all.js"></script>
	<script charset="utf-8" src="${pageContext.request.contextPath }/lib/kindeditor/lang/zh-CN.js"></script>
    
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <style>
  	.my-upload {
  		display: block;
  		width: 100px;
  		height: 32px;
  		text-align: center;
  		margin-top: 10px;
  		background-color: red;
  		color:#ffffff;
  		line-height:32px;
  		font-size: 16px;
  	}
  	.my-position {
  		display: block;
  		width: 400px;
  		height: 200px;
  	}
  	.my-position img {
  		display: block;
  		width: 100%;
  		height: 100%;
  	}
  </style>
  <body>
    <div class="x-body">
        <form class="layui-form" id="myForm">
          <div class="layui-form-item">
              <label for="goodsId" class="layui-form-label">
                  <span class="x-red">*</span>药品名称
              </label>
              <div class="layui-input-inline">
                   <select name="goodsId" class="input w50" id="orderBy">
	              <option value="">请选药品名称</option>
	              <c:if test="${not empty list}">
      				<c:forEach var="app" items="${list}" varStatus="st">
      			 	<option value="${app.id}">${app.goodsName}</option>
	              </c:forEach>
	              </c:if>
	              </select>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="picSort" class="layui-form-label">
                  <span class="x-red">*</span>排序
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="picSort" name="picSort" required="" lay-verify="number"
                  autocomplete="off" class="layui-input" value="${lunbo.picSort}">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="picUrl" class="layui-form-label">
                  <span class="x-red">*</span>轮播图片
              </label>
              <div class="layui-input-inline">
              		<span class="my-position" id="my_pic">
              			<img src="/images/pic_160.png" id="pic_back"/>
              		</span>
                  <input type="hidden" id="picUrl" name="picUrl" autocomplete="off" class="layui-input" value="${lunbo.picUrl}">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <input type="hidden" name="id" value="${lunbo.id}">
              <input type="hidden" name="goodsName" value="${lunbo.goodsName}" id="goodsName">
             <button  class="layui-btn" lay-filter="add" id="my_add">
                  增加
              </button>
             
          </div>
      </form>
    </div>
    <script type="text/javascript">
    KindEditor.ready(function(K) {
		var editor = K.editor({
			uploadJson : '${pageContext.request.contextPath }/admin/kindUpload',//标识处理图片的文件
			fileManagerJson :'${pageContext.request.contextPath }/admin/kindUpload',
			allowFileManager : true//允许上传文件和图片
		});
        K('#my_pic').click(function() {
			editor.loadPlugin('image', function() {
				editor.plugin.imageDialog({
					showRemote : false,
					clickFn : function(data) {
						console.log(data);
						K('#picUrl').val(data);
						$('#pic_back').attr("src",data);
						editor.hideDialog();
					}
				});
			});
		});
    })
    $(function(){
    	//回显时并不是真是数据的默认值
    	$("#orderBy option").each(function() { 
    		//console.log($(this).val());
    		if ($(this).val() == '${lunbo.goodsId}') { 
    		$(this).attr("selected", "selected"); 
    		} 
    		}); 
    })
    $('#my_add').click(function(){
   	 var myform =$('#myForm');
   	 var goodsId =$('#orderBy option:selected').val();
   	 var picSort=$('#picSort').val();
   	 if(goodsId==''){
   		layer.msg('必填项不能为空!');
      	return false;
   	 }else{
   		 var  goodsName =$('#orderBy option:selected').html();
   		 $('#goodsName').val(goodsName);
   	 }
   	 if(isNaN(picSort)){
        layer.msg('必须为数字!');
        return false;
      }
        var rr ="/admin/saveLunbo";
        $.post(rr,myform.serialize(),
                function (data) {
                    if('ok'==data){
                   	 parent.location.reload();
                        x_admin_close();
                    }
                }
            );  
        return false;
   })
	</script>
  </body>
</html>